package com.nit.generate;

import com.nit.tools.loop.NitLoopTools;

import java.util.Random;

/**
 * 字符串 生成器
 *
 * @Auth: 逆天开源-逍遥哥哥
 * @link: 1715656022@qq.com
 * @Date: 2023-07-11
 */
public class NitStringGenerator {
    private static final String BASE_STR = "abcdefghigklmnopkrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789";

    public static void main(String[] args) {
        NitLoopTools.loop(100, () -> {
            String str = NitStringGenerator.generate();
            System.out.println("随机字符串:" + str + "<br>");
        });
    }

    public static String generate() {
        return generate(NitNumberGenerator.generateInt(15, 30));
    }

    /**
     * @param length 目标字符串长度
     * @return 目标字符串
     */
    public static String generate(int length) {
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        NitLoopTools.loop(length, () -> sb.append(BASE_STR.charAt(random.nextInt(BASE_STR.length()))));
        return sb.toString();
    }
}
